<?php
/**
 * 处理用户对主题进行评论的请求
 *
 * @author Judas <judasnow@gmail.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */
session_start();
require_once( 'path.php' );
require_once( SOJ_ROOT.'/include/function/lib.php' );

@$request = $_POST;

try {
	$db = db_connect();
	$reply_process = new reply_process( $db , $request );

	if ( !empty( $_SESSION['username'] ) ){ 
		
		$username = $_SESSION['username'] ;

	}else{
		
		$username = 'anonymous' ;	
	}	

	$reply_process->set_reply_username( $username );
	//保存回复的同时
	//会触发对topic_process中的
	//reply_count加一的操作,即对
	//topic_process->plus_reply_count()
	//的调用
	$reply_process->save();

	$topic_no = $request['topic_no'] ;
	$topic_process = new topic_process( $db );
	$topic_process->load( 'topic_no' , $topic_no );

	$topic_process->plus_reply_count();
	$topic_process->save();

	$_SESSION['success_message'] = 'Reply success.';
	$_SESSION['url'] = "/soj/php/questions/topic_detail.php?topic_no=$topic_no" ;
	header( 'Location:../message_handle/success_handle.php' );
	exit ;

}catch( Exception $e ){
	
	 exception_handle( $e ) ;

}


